package com.jincheng.system.domain;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.jincheng.common.annotation.Excel;
import com.jincheng.common.core.domain.BaseEntity;
import com.jincheng.common.utils.bean.BeanUtils;
import com.jincheng.system.domain.dto.ActivityDetailDTO;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.io.Serial;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 活动对象 tb_activity
 *
 * @author DairyJay
 * @date 2025-02-24
 */
@Setter
@Getter
@TableName("tb_activity")
public class Activity extends BaseEntity {
    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 活动ID（主键，自增）
     */
    @TableId(type = IdType.AUTO)
    private Long activityId;

    /**
     * 活动名称
     */
    @Excel(name = "活动名称")
    private String activityName;

    /**
     * 部落ID（逻辑外键，引用tb_tribe表的tribe_id）
     */
    @Excel(name = "部落ID", readConverterExp = "逻辑外键，引用tb_tribe表的tribe_id")
    private Long tribeId;

    /**
     * 管理员ID
     */
    @Excel(name = "管理员ID", readConverterExp = "逻辑外键，引用tb_user表的user_id")
    private Long chairId;

    /**
     * 类型id
     */
    @Excel(name = "类型id")
    private Long typeId;

    /**
     * 参与对象
     */
    @Excel(name = "参与对象")
    private Integer participationObject;

    /**
     * 参与对象Text
     */
    @Excel(name = "参与对象Text")
    @TableField(exist = false)
    private String participationObjectName;

    /**
     * 参与部门
     */
    private String dept;

    /**
     * 参与部门
     */
    @Excel(name = "参与学院")
    private List<Long> deptList;


    /**
     * 类型名称
     */
    @TableField(exist = false)
    private String typeName;

    /**
     * 活动级别
     */
    @Excel(name = "级别")
    private Integer level;

    @TableField(exist = false)
    private String levelName;

    /**
     * 报名开始时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "报名开始时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date applyStartTime;

    /**
     * 报名结束时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "报名结束时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date applyEndTime;

    /**
     * 活动开始时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "活动开始时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date startTime;

    /**
     * 活动结束时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "活动结束时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    private Date endTime;


    /**
     * 参与年级
     */
    @Excel(name = "参与年级")
    private String grade;

    /**
     * 参与年级
     */
    @Excel(name = "参与年级")
    private List<Integer> gradeList;

    /**
     * 签到方式
     */
    private Integer signMethod;

    /**
     * 签到方式Text
     */
    @Excel(name = "签到方式")
    @TableField(exist = false)
    private String signMethodName;

    /**
     * 是否签退
     */
    @Excel(name = "是否签退")
    private Boolean isSignOut;

    /**
     * 积分
     */
    @Excel(name = "积分")
    private Long integral;

    /**
     * 是否需要审核
     */
    @Excel(name = "是否需要审核")
    private Boolean isCheck;

    /**
     * 可参与人数
     */
    @Excel(name = "可参与人数")
    private Long quantity;

    /**
     * 活动地点（缩略图）
     */
    private String location;

    /**
     * 活动地点
     */
    private String locationText;

    /**
     * 定位范围
     */
    private Integer signRadius;

    /**
     * 活动地点
     */
    @Excel(name = "活动地点")
    private String address;

    /**
     * 活动描述（可为空）
     */
    @Excel(name = "活动描述", readConverterExp = "可=为空")
    private String description;

    /**
     * 活动图片URL（可为空）
     */
    @Excel(name = "活动图片URL", readConverterExp = "可=为空")
    private String imageUrl;

    /**
     * 逻辑删除
     */
    private Integer delFlag;

    public void setDept(String dept) {
        this.dept = dept;
        this.deptList = (dept == null || dept.trim().isEmpty())
                ? new ArrayList<>()
                : Arrays.stream(dept.split(","))
                .map(String::trim)
                .map(Long::parseLong)
                .collect(Collectors.toList());
    }


    public void setDeptList(List<Long> deptList) {
        this.deptList = deptList;
        this.dept = deptList == null
                ? null
                : deptList
                .stream().map(String::valueOf)
                .collect(Collectors.joining(","));
    }


    public void setGrade(String grade) {
        this.grade = grade;
        this.gradeList = (grade == null || grade.trim().isEmpty())
                ? new ArrayList<>()
                : Arrays.stream(grade.split(","))
                .map(Integer::parseInt)
                .collect(Collectors.toList());
    }

    public void setGradeList(List<Integer> gradeList) {
        this.gradeList = gradeList;
        this.grade = gradeList == null
                ? null
                : gradeList
                .stream().map(String::valueOf)
                .collect(Collectors.joining(","));
    }
    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("activityId", getActivityId())
                .append("activityName", getActivityName())
                .append("organizerId", getTribeId())
                .append("typeId", getTypeId())
                .append("applyStartTime", getApplyStartTime())
                .append("applyEndTime", getApplyEndTime())
                .append("startTime", getStartTime())
                .append("endTime", getEndTime())
                .append("level", getLevel())
                .append("levelName", getLevelName())
                .append("participationObjectName", getParticipationObject())
                .append("participationObjectName", getParticipationObjectName())
                .append("dept", getDept())
                .append("grade", getGrade())
                .append("signMethod", getSignMethod())
                .append("signMethodName", getSignMethodName())
                .append("isSignOut", getIsSignOut())
                .append("integral", getIntegral())
                .append("isCheck", getIsCheck())
                .append("quantity", getQuantity())
                .append("location", getLocation())
                .append("address", getAddress())
                .append("locationText", getLocationText())
                .append("signRadius", getSignRadius())
                .append("description", getDescription())
                .append("imageUrl", getImageUrl())
                .append("delFlag", getDelFlag())
                .append("createBy", getCreateBy())
                .append("createTime", getCreateTime())
                .append("updateBy", getUpdateBy())
                .append("updateTime", getUpdateTime())
                .toString();
    }
}
